<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>返回数组中指定元素的下标</title>
</head>
<body>
    <script>
        var find=prompt("请输入你想查找的字母：");
        var arr=['c','s','s','e','r','r','v','v','b','w','e','c','d'];
        var num=0;
        function findall(){//返回所有索引下标
            document.write("出现该元素的下标为:");
            for(i=0;i<=arr.length;i++){
                if(find==arr[i]){
                    document.write((i+1)+"\t");
                }
            }
        }
        function count(){
            document.write("该元素出现的次数为：")
            for(i=1;i<=arr.length;++i){
                if(find==arr[i-1]){
                    ++num;
                }
            }  document.write(num);
        }
        findall();
        count();
    </script>
</body>
</html>